<template>
	<view class="page">
    <u-subsection :list="list" :current="curNow" @change="sectionChange"></u-subsection>
    <view  v-for="(item,index) in recycleList"  :key="index" >
      <view carBox-item style="position: relative; padding: 10px 10px; border: 1px solid #4d4640;border-radius: 20px;margin: 10px 10px;" >
						  <view>
                <view style="margin-top: 3px;">预约日期{{ item.dataSpan }}</view>
                <view style="margin-top: 3px;">预约时间{{ item.timeSpan }}</view>
                <view  style="margin-top: 3px;" >姓名{{item.ordername}}</view>
							  <view style="margin-top: 3px;">电话{{ item.phone }}</view>
                <view style="margin-top: 3px;">地址{{ item.address }}</view>
                <button v-if="curNow ==0" style="position: absolute;top: 0;right: 0; width: 100px;border-radius: 20px;" @click="goOff(item)">取消订单</button>
                <button v-if="curNow ==2" style="width: 100px;border-radius: 20px;margin-top: 20px;" @click="goAfter()">常见问题</button>
						  </view>
        </view>
    </view>
	</view>
</template>

<script>
import {baseUrl} from '@/config'
export default {

	data() {
		return {
      userId:'',
      list: ['待接单', '待上门', '已完成'],
      curNow: 0,
      status:0,
      recycleList:[]
		};
	},
  beforeCreate(){
      this.userId=uni.getStorageSync('user').data[0].userId
      uni.request({
              url: baseUrl+'/v1/recycle/orderStatusSearch',
              data:{
                userId:this.userId,
                status:0
              },
              success: (res) => {
                this.recycleList = res.data.data
                }
          });
  },
	onShow() {
    this.getRecycleList()
  },
	
	methods: {
    goAfter(){
      uni.navigateTo({
        url:'/pages/after/index'
      })
    },
    goOff(item){
      uni.request({
              url: baseUrl+'/v1/recycle/orderDelete',
              data:{
                id:item.id
              },
              success: () => {
              this.getRecycleList()
              }
          });
    },
    sectionChange(index) {
				this.curNow = index;
        this.status = this.curNow
        this.getRecycleList()
			},
    getRecycleList(){
      this.userId=uni.getStorageSync('user').data[0].userId
      uni.request({
              url: baseUrl+'/v1/recycle/orderStatusSearch',
              data:{
                userId:this.userId,
                status:this.status
              },
              success: (res) => {
                if(res.data.code == 200){
                  this.recycleList = res.data.data
                }else{
                  this.recycleList = []
                }
                
                }
          });
          
    }
	}
};
</script>

<style lang="scss" scoped>

</style>
